/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modul.pencatatan.datadvd;

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.net.URL;
public class Painter extends java.awt.Canvas {

    Image image;

    public void setImage(String file) {
        URL url = null;
        try {
            url = new File(file).toURI().toURL();
        } catch (Exception e) {
        }
        image = getToolkit().getImage(url);
        repaint();
    }

    @Override
    public void paint(Graphics g) {
        try {
            double d = image.getHeight(this) / this.getHeight();
            double w = image.getWidth(this) / d;
            double x = this.getWidth() / 2 - w / 2;
            g.drawImage(image, (int) x, 0, (int) (w), this.getHeight(), this);
        } catch (Exception e) {
        }
    }
}